<?php

/**
 * @author Immanuel Bauer | 0626117
 */
class UserJSON {
	
	/**
	 * Generates the JSON view for the given User model object.
	 * @param User $user
	 * @return string
	 */
	public static function getView($user, $count = null){
		if(is_array($user)){
			$a = array();
			$uc = count($user);
			for($c = 0; $c < $uc; $c++){
				$u = $user[$c];
				$ua = array(
					'uID' => $u->getID(),
					'fN' => $u->getFirstName(),
					'lN' => $u->getLastName(),
					'nick' => $u->getLoginName(),
					'email' => $u->getEmail()
				);	
				array_push($a, $ua);
			}
			$res = new ResultJSON(false, session_id());
			$res->addItem('u', $a);
			if(!is_null($count)) $res->addItem('uC', $count);
			return $res->renderView();
		} else {
			$a = array(
					'uID' => $user->getID(),
					'fN' => $user->getFirstName(),
					'lN' => $user->getLastName(),
					'email' => $user->getEmail(),
					'nick' => $user->getLoginName(),
					'group' => $user->getGroup(),
					'online' => ($user->isOnline())?'true':'false'
				);		
			
				
			$res = new ResultJSON(false, session_id());
			$res->addItem('u', $a);
			
			return $res->renderView();
		}
	}
	
}

?>